/**
* \file
*/
#include "precompiled.hpp"
#include "Exception.hpp"
#include <cstdarg>
#include <cstring>

std::size_t const Error::buffer_length = 1024;
std::size_t const Exception::buffer_length = 1024;
using std::string;


Error::Error(int arg_error, const char* fmt_string, ...)
:
    runtime_error("Error"),
    m_error(arg_error)
{
    char buffer[buffer_length];
    va_list args;
    va_start(args, fmt_string);

    vsnprintf(buffer, sizeof(buffer), fmt_string, args);
    buffer[sizeof(buffer) - 1] = '\0';

    va_end(args);

    string errorName = strerror(m_error);
    m_msg = errorName + ": ";
    m_msg += buffer;
}


Exception::Exception(const char* fmt_string, ...)
{
    char buffer[buffer_length];
    va_list args;
    va_start(args, fmt_string);

    vsnprintf(buffer, sizeof(buffer), fmt_string, args);
    buffer[sizeof(buffer) - 1] = '\0';

    va_end(args);

    msg = buffer;
}

